/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manager;

import entity.Book;
import entity.Orders;
import entity.OrdersDetails;
import iface.IManager;
import java.util.ArrayList;

/**
 *
 * @author User
 */
public class OrdersDetailsManager implements IManager<OrdersDetails> {

    private Manager manager;
    private ArrayList<OrdersDetails> ordersDetailsList;

    public OrdersDetailsManager(Manager manager) {
        ordersDetailsList = new ArrayList<OrdersDetails>();
        this.manager = manager;
    }

    @Override
    public void add(OrdersDetails obj) {
        this.ordersDetailsList.add(obj);
    }

    @Override
    public void remove(OrdersDetails obj) {
        this.ordersDetailsList.remove(obj);
        obj.setStatus(false);
        this.manager.getDisabledOrdersDetailsManager().add(obj);
    }

    @Override
    public OrdersDetails replace(int index, OrdersDetails obj) {
        return this.ordersDetailsList.set(index, obj);
    }

    @Override
    public int size() {
        return this.ordersDetailsList.size();
    }

    @Override
    public OrdersDetails get(int index) {
        return this.ordersDetailsList.get(index);
    }
    
    public ArrayList<OrdersDetails> getListOrdersDetailsUnpaid(int ordersID) {
        ArrayList<OrdersDetails> alDetails = new ArrayList<OrdersDetails>();
        for(OrdersDetails details: this.ordersDetailsList) {
            if(details.getOrdersID() == ordersID && details.getReturnDate() == null) alDetails.add(details);
        }
        return alDetails;
    }
    
    public ArrayList<OrdersDetails> getListOrdersDetailsUnpaid(ArrayList<Orders> alOrders) {
        ArrayList<OrdersDetails> alDetails = new ArrayList<OrdersDetails>();
        for(Orders orders: alOrders) {
            alDetails.addAll(this.getListOrdersDetailsUnpaid(orders.getOrdersID()));
        }
        return alDetails;
    }
    
    public ArrayList<OrdersDetails> getListOrdersDetailsPaid(int ordersID) {
        ArrayList<OrdersDetails> alDetails = new ArrayList<OrdersDetails>();
        for(OrdersDetails details: this.ordersDetailsList) {
            if(details.getOrdersID() == ordersID && details.getMoney() > 0) alDetails.add(details);
        }
        return alDetails;
    }
    
    public ArrayList<OrdersDetails> getListOrdersDetailsPaid(ArrayList<Orders> alOrders) {
        ArrayList<OrdersDetails> alDetails = new ArrayList<OrdersDetails>();
        for(Orders orders: alOrders) {
            alDetails.addAll(this.getListOrdersDetailsPaid(orders.getOrdersID()));
        }
        return alDetails;
    }
    
    public ArrayList<OrdersDetails> getListOrdersDetails(int ordersID) {
        ArrayList<OrdersDetails> alDetails = new ArrayList<OrdersDetails>();
        for(OrdersDetails details: this.ordersDetailsList) {
            if(details.getOrdersID() == ordersID) alDetails.add(details);
        }
        return alDetails;
    }
    
    public ArrayList<OrdersDetails> getListOrdersDetailsByOrdersList(ArrayList<Orders> alOrders) {
        ArrayList<OrdersDetails> alDetails = new ArrayList<OrdersDetails>();
        for(Orders orders: alOrders) {
            alDetails.addAll(this.getListOrdersDetails(orders.getOrdersID()));
        }
        return alDetails;
    }
    
    public ArrayList<OrdersDetails> getByBookID(ArrayList<Book> alBook) {
        ArrayList<OrdersDetails> alDetails = new ArrayList<OrdersDetails>();
        for(Book book: alBook) {
            alDetails.addAll(this.getByBookID(book));
        }
        return alDetails;
    }
    
    public ArrayList<OrdersDetails> getByBookID(Book book) {
        ArrayList<OrdersDetails> alDetails = new ArrayList<OrdersDetails>();
        for(OrdersDetails details: this.ordersDetailsList) {
            if(book.getBookID() == details.getBookID()) {
                alDetails.add(details);
            }
        }
        return alDetails;
    }
    
    public boolean getReturnedOrders(int ordersID) {
        for(OrdersDetails details: this.ordersDetailsList) {
            if(details.getOrdersID() == ordersID && details.getReturnDate() == null)
                return false;
        }
        return true;
    }

    public ArrayList<OrdersDetails> getByOrdersID(int ordersID) {
        ArrayList<OrdersDetails> alDetails = new ArrayList<OrdersDetails>();
        for(OrdersDetails details: this.ordersDetailsList) {
            if(details.getOrdersID() == ordersID)
                alDetails.add(details);
        }
        return alDetails;
    }
    
}
